package com.yimi.yinhepda.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yimi.yinhepda.R;
import com.yimi.yinhepda.entity.response.DifferScanResponse;

import java.util.List;

/**
 * @author 000432
 * @date 2017/4/17 0017
 *
 * 差异扫描处理adapter
 */

public class DifferScanDealAdapter extends BaseAdapter {

  private Context context;
  private List<DifferScanResponse.DifferScanEntity> mDataList;

  public DifferScanDealAdapter(Context context, List<DifferScanResponse.DifferScanEntity> mDataList) {
    this.context = context;
    this.mDataList = mDataList;
  }

  @Override public View getView(int i, View convertView, ViewGroup viewGroup) {
    ViewHolder holder = null;
    if (convertView == null) {
      holder = new ViewHolder();
      convertView = LayoutInflater.from(context).inflate(R.layout.load_scan_item2, null);
      // 运单号
      holder.waybillnum = (TextView) convertView.findViewById(R.id.text1);
      //包装
      holder.packaging = (TextView) convertView.findViewById(R.id.text2);
      //少货
      holder.missingNums = (TextView) convertView.findViewById(R.id.text3);
      // 已扫
      holder.scaned = (TextView) convertView.findViewById(R.id.text4);
      // 差异
      holder.differ = (TextView) convertView.findViewById(R.id.text5);
      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }
    DifferScanResponse.DifferScanEntity item = mDataList.get(i);
    // 运单号
    holder.waybillnum.setText(item.getWaybillNo());
    //包装
    holder.packaging.setText(item.getPackingSpecification());
    //少货
    holder.missingNums.setText(item.getLessNum() + "");
    // 已扫
    holder.scaned.setText(item.getScannedNum() + "");
    // 差异
    holder.differ.setText((item.getScannedNum() - item.getLessNum()) + "");
    //处理颜色
    int color = item.getColorInt();
    switch (color) {
      case 0:
        convertView.setBackgroundColor(context.getResources().getColor(R.color.red));
        break;
      case 1:
        convertView.setBackgroundColor(context.getResources().getColor(R.color.white));
        break;
      case 2:
        convertView.setBackgroundColor(context.getResources().getColor(R.color.yellow));
        break;
      case 3:
        convertView.setBackgroundColor(context.getResources().getColor(R.color.green));
        break;
      default:
        break;
    }
    return convertView;
  }

  static class ViewHolder {
    /** 运单号 */
    TextView waybillnum;
    /** 包装 */
    TextView packaging;
    /** 少货 */
    TextView missingNums;
    /** 已扫 */
    TextView scaned;
    /** 差异 */
    TextView differ;
  }

  @Override public long getItemId(int i) {
    return i;
  }

  @Override public Object getItem(int i) {
    return mDataList.get(i);
  }

  @Override public int getCount() {
    return mDataList.size();
  }
}
